package com.znufe.exam.controller.h5;

import com.znufe.exam.base.BaseApiController;
import com.znufe.exam.base.RestResponse;
import com.znufe.exam.domain.grade.StudentExamDetailRequestObject;
import com.znufe.exam.domain.grade.StudentExamQuestionAnswerObject;
import com.znufe.exam.service.ExamGradeService;
import com.znufe.exam.service.ExamPaperService;
import com.znufe.exam.viewmodel.admin.exam.ExamPaperEditRequestVM;
import com.znufe.exam.viewmodel.admin.grade.*;
import com.znufe.exam.viewmodel.admin.question.QuestionEditRequestVM;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@Api(description = "查询答题结果", value = "查询答题结果")
@RestController("H5ExamResultController")
@RequestMapping(value = "/api/h5/result")
public class H5ExamResultController extends BaseApiController {

    @Autowired
    private final ExamGradeService examGradeService;
    @Autowired
    private final ExamPaperService examPaperService;

    public H5ExamResultController(ExamGradeService examGradeService, ExamPaperService examPaperService) {
        this.examGradeService = examGradeService;
        this.examPaperService = examPaperService;
    }

//    @RequestMapping(value = "/get_student_individual_grade", method = RequestMethod.POST, produces = "application/json")
//    @ApiOperation(value = "通过学生id获得某个学生的个人成绩（学生id查找）",
//            notes = "获取某个学生的个人成绩[student_individual_grade_info]，作者：yang shuo")
//    public RestResponse<List<StudentIndividualGradeResponseVM>> getStudentIndividualGrade(@RequestBody StudentIndividualGradeRequestVM model) {
//        model = StudentIndividualGradeRequestVM.wipeBlank(model);
//        List<StudentIndividualGradeResponseVM> responseVM = examGradeService.getStudentIndividualGradeInfo(model);
//        return RestResponse.ok(responseVM);
//    }
//
//    @RequestMapping(value = "/get_student_exam_detail", method = RequestMethod.POST, produces = "application/json")
//    @ApiOperation(value = "通过学生id、试卷id获得某个学生的答卷详情（按学生id、试卷id查找）",
//            notes = "获取某个学生生的某张试卷的答卷情况[t_exam_paper_question_customer_answer]，作者：yang shuo")
//    public RestResponse<List<StudentExamDetailResponseVM>> getStudentExamDetail(@RequestBody StudentExamDetailRequestVM model) {
//        ExamPaperEditRequestVM examPaperEditRequestVM = examPaperService.examPaperToVM(model.getExamPaperId());
//        List<QuestionEditRequestVM> questionList = examPaperEditRequestVM.getTitleItems()
//                .get(0).getQuestionItems();
//
//        List<StudentExamDetailResponseVM> vmList = questionList.stream().map(q -> {
//            StudentExamDetailResponseVM vm = modelMapper.map(q, StudentExamDetailResponseVM.class);
//            vm.setQuestionId(q.getId());
//            //System.out.println(vm.toString() + "     " +  vm.getQuestionId());
//            return vm;
//        }).collect(Collectors.toList());
//
//        StudentExamDetailRequestObject obj = modelMapper.map(model, StudentExamDetailRequestObject.class);
//        for (StudentExamDetailResponseVM vm : vmList) {
//            obj.setQuestionId(vm.getQuestionId());
//            StudentExamQuestionAnswerObject answer = examGradeService.selectStuAns(obj);
//            if (answer == null) {
//                vm.setStudentAnswer("学生未作答");
//                vm.setStudentScore(0);
//            } else {
//                vm.setStudentAnswer(answer.getStuAnswer());
//                vm.setStudentScore(answer.getStuScore());
//            }
//        }
//        return RestResponse.ok(vmList);
//    }
}
